package com.pks.insurance.util;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * Used for obtaining Session for Hiberate.
 * 
 * @author Pankaj Soni
 * 
 */
/**
 * @author VAIO
 * 
 */
final public class HibernateUtil {

	/**
	 * Prevents object creation
	 */
	private HibernateUtil() {

	}

	private static final Logger LOGGER = Logger.getLogger(HibernateUtil.class);
	private static final SessionFactory SESSION_FACTORY;
	static {
		try {
			SESSION_FACTORY = new AnnotationConfiguration().configure()
					.buildSessionFactory();
		} catch (Exception ex) {
			LOGGER.error("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	/**
	 * @return the sessionFactory
	 */
	public static SessionFactory getSessionFactory() {
		return SESSION_FACTORY;
	}

	/**
	 * @return the session from sessionFactory
	 */
	public static org.hibernate.Session getSession() {
		return SESSION_FACTORY.openSession();
	}
}